package com.gel.aiagent.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gel.aiagent.dao.mapper.UserDOMapper;
import com.gel.aiagent.convention.exception.ClientException;
import com.gel.aiagent.dao.UserDO;
import com.gel.aiagent.dto.req.UserRegisterDTO;
import com.gel.aiagent.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserDOMapper, UserDO> implements UserService {
    @Override
    public void register(UserRegisterDTO requestParam) {
        LambdaQueryWrapper<UserDO> queryWrapper = Wrappers.lambdaQuery(UserDO.class)
                .eq(UserDO::getUsername, requestParam.getUsername());
        UserDO userDO = baseMapper.selectOne(queryWrapper);
        if (userDO!=null) {
            throw new ClientException("用户名已存在");
        }
        int insert = baseMapper.insert(BeanUtil.toBean(requestParam, UserDO.class));
        if(insert <0){
            throw new ClientException("注册失败");
        }


    }
}
